<template>
	<view class="page">
		<status-bar :title='title'></status-bar>
		<backTop v-if='showBackTop'></backTop>
		<view class="list">
			<view v-for="(item,index) in lessonList" :key='index' @click="toDetail(item.lesson_id)" class="lesssonItem">
				<view class="flex">
					<view class="studying" v-if='item.order_status == 1'>学习中</view>
					<view class="lesson-title lesson-title-sm" :class="{study:item.order_status == 1}">{{item.lesson_title}}</view>
					<view class="lesson-info">{{item.lesson_info}}</view>
					<view class="flex-box align-center flex-between tags">
						<text class="yellow">{{item.lesson_length?item.lesson_length:'0:00'}}</text>
						<text class="price">{{item.lesson_price}}</text>
					</view>
				</view>
			</view>
		</view>
		<Empty v-if='noData' txt='没有收藏该类型的课程'></Empty>
	</view>
</template>

<script>
	let that;
	export default {
		data() {
			return {
				title:'',
				lessonList: '',
				noData: false,
				class_id: '',
				showBackTop: false
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 500) {
				this.showBackTop = true
			} else {
				this.showBackTop = false
			}
		},
		onLoad(e) {
			that = this
			this.class_id = e.cid;
			this.getHomeData()
			
		},
		onShow() {
			this.getHomeData()
		},
		methods: {
			toDetail(id){
				let bid = uni.getStorageSync('bid');
				// #ifdef H5
				window.location.href = 'https://sra.weikebaba.com/index.php/singleSaleLesson/index?veriCode='+bid+'&pageType=1&id='+id
				// #endif
			},
			getHomeData() {
				that.noData = false;
				that.lessonList = '';
				that.$http.get({
					url: '/zzj_singleSaleApi/my_collect_lesson',
					data: {
						bid: uni.getStorageSync('bid'),
						v_id: uni.getStorageSync('vid'),
						class_id: that.class_id
					}
				}).then(res => {
					if (res.code == 100 && res.data) {
						that.lessonList = res.data.lesson
						uni.setNavigationBarTitle({
							title: res.data.class_name + '（' + res.data.num + '）'
						})
						that.title = res.data.class_name + '（' + res.data.num + '）'
					} else {
						uni.setNavigationBarTitle({
							title: '课程收藏详情'
						})
					}
					if (!that.lessonList || that.lessonList.length < 1) {
						that.noData = true
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: $uni-page-space;
		.lesssonItem{
			padding: $uni-page-space;
			background-color: #FFFFFF;
			border-radius: 8rpx;
			box-shadow:  0 0 3px 0 rgba(0,0,0,.1);
			margin-bottom: $uni-page-space;
			display: flex;
			position: relative;
			.lessonImg{
				width: 200rpx;
				height: 200rpx;
				margin-right: $uni-page-space;
			}
			.tags{
				margin-top: 20rpx;
				text{
					margin-right: 10rpx;
					line-height: 36rpx;
					border-radius: 36rpx;
					height: 36rpx;
					display: inline-block;
					font-size: 24rpx;
					padding: 0 16rpx;
				}
				.green{	
					background-color: #E3FBF0;
					color: #01D475;
				}
				.yellow{
					background-color: #FEF7EB;
					color: #F8AD24;
				}
				.red{
					background-color: #FEEFEF;
					color: #DE5858;
				}
				.gray{
					background-color: #EEEEEE;
					color: #666666;
				}
				.price {
					padding: 0;
					margin-right: 0;
					color: #FF0000;
					font-size: 34rpx;
					font-weight: bold;
				}
			}
			.tag{
				position: absolute;
				width: 24rpx;
				top: 0;
				height: 20rpx;
				right: 20rpx;
				background-color: $tag-bg;
				border-radius: 0 0 8rpx 8rpx;
				margin-bottom: 20rpx;
			}
			.lesson-title{
				font-size: 34rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
				line-height: 48rpx;
				text-align: justify;
			}
			.lesson-title-sm{
				font-size: 28rpx;
			}
			.lesson-info{
				font-size: 24rpx;
				color: #666666;
				text-align: justify;
			}
			
			// 学习中
			.study{
				padding-right: 70rpx;
			}
			.studying{
				color: #01D475;
				background-color: #E3FBF0;
				line-height: 36rpx;
				font-size: 24rpx;
				height: 36rpx;
				display: block;
				padding: 0 4rpx 0 12rpx;
				border-radius: 32rpx 0 0 32rpx;
				position: absolute;
				right: 0;
				top: 20rpx;
			}
		}
	}
</style>
